home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / ISSUE02 / TPACK / TPACK.ZIP / LOGINDLG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-06-01  |  3.7 KB  |  122 lines

  1. {------------------------------------------------------------------------------}
  2. {UNREGISTERED VERSION (6/1/95) PLEASE REDISTRIBUTE IN tPACK.ZIP!
  3.  This revision does not contain everything, nor are the exciting
  4.  DataSetReporter and ExtendedMenu[Item] components included.
  5.  Use SWREG#5906 to receive these, icons and a help file for $130.
  6.  You must register when using this code in a business application!
  7.  You'll receive a license to use this code in up to 50 copies of
  8.  any app you write. In turn you will get responsive e-mail
  9.  tech support and enhancements till I run out of registrations
  10.  or suggestions. Meanwhile.. enjoy the code. Bye! I'll make more.
  11.  {(C)'1995 Michael/Ax-Systems, 71560,1754@Compuserve.com}
  12. {------------------------------------------------------------------------------}
  13.  
  14. unit LoginDlg;
  15.  
  16. interface
  17.  
  18. uses WinTypes, WinProcs, Classes, Graphics, Forms, Controls, StdCtrls,
  19.   Buttons, dbiTypes
  20. , UserInfo, MiscComp;
  21.  
  22. {------------------------------------------------------------------------------}
  23. {                                                                              }
  24. {------------------------------------------------------------------------------}
  25.  
  26. type
  27.   TLoginDialogForm = class(TDemoForm)
  28.     Label1: TLabel;
  29.     Password: TEdit;
  30.     OKBtn: TBitBtn;
  31.     CancelBtn: TBitBtn;
  32.     Label2: TLabel;
  33.   private
  34.     { Private declarations }
  35.   public
  36.     { Public declarations }
  37.   end;
  38.  
  39. {------------------------------------------------------------------------------}
  40. {                                                                              }
  41. {------------------------------------------------------------------------------}
  42.  
  43.   TLoginDialog = class(TDialogShell)
  44.   private
  45.     fPassword: string;
  46.         {type plain/network/windows; include screen save pw coder and tests against bindery}
  47.     fRetries: Integer;
  48.     fRequired: Boolean;
  49.     fPasswordOk: Boolean;
  50.     fCaseSensitive: Boolean;
  51.   protected
  52.   public
  53.     constructor Create(aOwner:Tcomponent); Override;
  54.     procedure Execute; Override;
  55.     function Login(MasterPassword:String):Boolean;
  56.   published
  57.     property CaseSensitive: Boolean read fCaseSensitive write fCaseSensitive;
  58.     property PassWord: String read fPassWord write fPassword;
  59.     property PassWordOk: Boolean read fPassWordOk write fPasswordOk stored false;
  60.     property Required: Boolean read fRequired write fRequired default true;
  61.     property Retries: Integer read fRetries write fRetries default 2;
  62.     end;
  63.  
  64. {------------------------------------------------------------------------------}
  65. {                                                                              }
  66. {------------------------------------------------------------------------------}
  67.  
  68. implementation
  69.  
  70. uses SysUtils;
  71.  
  72. {$R *.DFM}
  73.  
  74.  
  75. constructor TLoginDialog.Create(aOwner:TComponent);
  76. begin
  77.   inherited Create(aOwner);
  78.   fRequired:=True;
  79.   fRetries:=2;
  80. end;
  81.  
  82. procedure TLoginDialog.Execute;
  83. var
  84.   Cursor:TCursor;
  85.   i: integer;
  86. begin
  87.   if (not fRequired) or (fPassword='') then begin
  88.     fPasswordOk:=True;
  89.     exit;
  90.     end;
  91.   fPasswordOk:=False;
  92.   Cursor:=Screen.Cursor;
  93.   Screen.Cursor:=crDefault;
  94.   With TLoginDialogForm.Create(Application) do try
  95.     for i:=0 to fRetries do begin
  96.       Password.SelectAll;
  97.       if ShowModal<>IdOk then
  98.         break;
  99.       if fCaseSensitive then
  100.         fPasswordOk:= (Password.Text=fPassword)
  101.       else
  102.         fPasswordOk:= (uppercase(Password.Text)=uppercase(fPassword));
  103.       if fPasswordOk then
  104.         break;
  105.       end;
  106.   finally
  107.     Free;
  108.     end;
  109.   Screen.Cursor:=Cursor;
  110. end;
  111.  
  112. function TLoginDialog.Login(MasterPassword:String):boolean;
  113. begin
  114.   fPassWord:= MasterPassword;
  115.   Execute;
  116.   fPassword:='';
  117.   Result:= fPasswordOk;
  118. end;
  119.  
  120. end.
  121.  
  122.